package com.shujia.wyh.day09;

import java.util.ArrayList;
import java.util.Collection;

/*
        boolean addAll(Collection c)
        boolean removeAll(Collection c)
        boolean containsAll(Collection c)
        boolean retainAll(Collection c)

 */
public class CollectionDemo2 {
    public static void main(String[] args) {
        //1、创建集合对象
        Collection c1 = new ArrayList();

        //2、创建元素并将元素添加到集合
        c1.add("hello");
        c1.add("world");
        c1.add("java");
        c1.add("hadoop");

        System.out.println("c1: "+c1);

        //boolean addAll(Collection c)
        Collection c2 = new ArrayList();
        c2.add("hadoop");
        c2.add("hive");
        c2.add("hbase");
        System.out.println("c2: "+c2);
        System.out.println("===============================");

//        c1.addAll(c2); //在末尾处添加
//        System.out.println(c1);
//
//        //boolean removeAll(Collection c)
//        c1.removeAll(c2);
//        System.out.println(c1);
//
////        c1.add("hadoop");
//        //boolean containsAll(Collection c)
//        System.out.println(c1.containsAll(c2));

        //boolean retainAll(Collection c)
        System.out.println(c1.retainAll(c2));  // c1交上c2，将交集保存在c1中，c2不动
        System.out.println("c1: "+c1);
        System.out.println("c2: "+c2);

    }
}
